package gokyesil.game.aygitciklar.model;

import java.util.ArrayList;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.World;

public abstract class Box
{
	public TextureRegion textureRegion;
	public float width;
	public float height;
	public float health;
	public float density;
	public Body body;
	
	public void createBody(World physWorld, float _posX, float _posY)
	{
		health = 0.1f;
		width = 1.0f;
		height = 1.0f;
		density = 6.0f;
		BodyDef bodyDef = new BodyDef();
	    bodyDef.type = BodyType.DynamicBody;
		bodyDef.position.set(_posX, _posY);
	    body = physWorld.createBody(bodyDef);
	    PolygonShape dynamicBox = new PolygonShape();
	    dynamicBox.setAsBox(width/2.0f, height/2.0f);
	    FixtureDef fixtureDef = new FixtureDef();
	    fixtureDef.shape = dynamicBox;
	    fixtureDef.density = density; 
	    fixtureDef.friction = 0.3f;
	    fixtureDef.restitution = 0.16f;
	    body.createFixture(fixtureDef);
	    
	}
	public void loadTexture(String textureName, TextureAtlas atlas)
	{
		textureRegion = atlas.findRegion(textureName);
	}
	public void render(SpriteBatch spriteBatch, TextureRegion textureRegion)
	{
		spriteBatch.draw(textureRegion, body.getPosition().x-width/2.0f, body.getPosition().y-height/2.0f, width/2.0f, height/2.0f, width, height, 1, 1, (float)(body.getAngle()*180/Math.PI));
	}
}
